package com.atguigu.eduteacher.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduteacher.javabean.SubjectNestedDto;
import com.atguigu.eduteacher.service.EduSubjectService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-15
 */
@RestController
@RequestMapping("/eduservice/edu-subject")
@RequiredArgsConstructor
@CrossOrigin
public class EduSubjectController {

    private final EduSubjectService subjectService;

    @ApiOperation(value = "Excel批量导入")
    @PostMapping
    public R addSubject(MultipartFile file) {
        //1 获取上传的excel文件 MultipartFile
        //返回错误提示信息
        subjectService.importSubjectData(file);
        //判断返回集合是否为空
        return R.ok();
    }

    @ApiOperation(value = "嵌套数据列表")
    @GetMapping("")
    public R nestedList(){
        List<SubjectNestedDto> subjectNestedDtoList = subjectService.nestedList();
        return R.ok().data("items", subjectNestedDtoList);
    }

}
